package com.aiju.cash.core.api;

import com.aiju.app.config.ConfigManager;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

/**
 * @author: 佐为
 * @date: 2016-12-07 15:03
 * @version: V1.0
 * @Description: 会员
 */
public class MemberApi {

    private String cardList = ConfigManager.INIT_SERVER_HOST + "/mcard/list";
    private String cardSave = ConfigManager.INIT_SERVER_HOST + "/mcard/save";
    private String cardGet = ConfigManager.INIT_SERVER_HOST + "/mcard/get";
    private String bindCard = ConfigManager.INIT_SERVER_HOST + "/member/bindCard";
    private String cardDelete = ConfigManager.INIT_SERVER_HOST + "/mcard/delete";
    private String cardUpdate = ConfigManager.INIT_SERVER_HOST + "/mcard/update";

    private String memberList = ConfigManager.INIT_SERVER_HOST + "/member/list";
    private String memberSave = ConfigManager.INIT_SERVER_HOST + "/member/saveMember";
    private String memberGet = ConfigManager.INIT_SERVER_HOST + "/member/get";
    private String memberUpdate = ConfigManager.INIT_SERVER_HOST + "/member/update";

    private String getByMCardId = ConfigManager.INIT_SERVER_HOST + "/member/getByMCardId";
    private String getByCondition = ConfigManager.INIT_SERVER_HOST + "/member/getByCondition";

    /**
     * 会员卡修改接口
     */
    public void updateCard(String id, String status, String token, StringCallback callback) {
        OkHttpUtils
                .post()
                .url(cardUpdate)
                .addParams("id", id)
                .addParams("status", status)
                .addParams("token", token)
                .build()
                .execute(callback);
    }

    /**
     * 会员绑定会员卡（已存在会员，新增会员卡时使用）
     */
    public void bindCard(String memberId, String mCardId, String code, String token, StringCallback callback) {
        OkHttpUtils
                .post()
                .url(bindCard)
                .addParams("memberId", memberId)
                .addParams("mCardId", mCardId)
                .addParams("code", code)
                .addParams("token", token)
                .build()
                .execute(callback);
    }

    /**
     * 会员信息接口
     *
     * @param token 令牌
     */
    public void memberGet(String id, String token, StringCallback callback) {
        OkHttpUtils
                .post()
                .url(memberGet)
                .addParams("id", id)
                .addParams("token", token)
                .build()
                .execute(callback);
    }

    /**
     * 会员修改
     *
     * @param token 令牌
     */
    public void memberUpdate(String id, String token, String name, String gender, String birthday,
                             String province, String city, String area, String address,
                             String remark, StringCallback callback) {
        OkHttpUtils
                .post()
                .url(memberUpdate)
                .addParams("id", id)
                .addParams("token", token)
                .addParams("gender", gender)
                .addParams("name", name)
                .addParams("birthday", birthday)
                .addParams("province", province)
                .addParams("city", city)
                .addParams("area", area)
                .addParams("address", address)
                .addParams("remark", remark)
                .build()
                .execute(callback);

    }

    /**
     * 会员添加接口（新建会员，选择会员卡情况使用该接口）
     *
     * @param token 令牌
     */
    public void memberAdd(String phone, String token, String storeId,
                          String gender, String name, String birthday, String province,
                          String city, String area, String address, String remark,
                          StringCallback callback) {
        OkHttpUtils
                .post()
                .url(memberSave)
                .addParams("phone", phone)
                .addParams("token", token)
                .addParams("storeId", storeId)
                .addParams("gender", gender)
                .addParams("name", name)
                .addParams("birthday", birthday)
                .addParams("province", province)
                .addParams("city", city)
                .addParams("area", area)
                .addParams("address", address)
                .addParams("remark", remark)
                .build()
                .execute(callback);

    }

    /**
     * 条件查询会员信息接口
     *
     * @param token 令牌
     * @param name  会员卡号
     */
    public void getByCondition(String token, String storeId, String name,  StringCallback callback) {
        OkHttpUtils
                .post()
                .url(getByCondition)
                .addParams("token", token)
                .addParams("storeId", storeId)
                .addParams("name", name)
                .build()
                .execute(callback);
    }

    /**
     * 会员卡获取会员列表接口
     *
     * @param token   会员卡id
     * @param mCardId 店铺编号
     */

    public void getByMCardId(String mCardId, String token, String currentNum, String pageSize, StringCallback callback) {
        OkHttpUtils
                .post()
                .url(getByMCardId)
                .addParams("mCardId", mCardId)
                .addParams("token", token)
                .addParams("currentNum", currentNum)
                .addParams("pageSize", pageSize)
                .build()
                .execute(callback);
    }

    /**
     * 会员卡详情
     *
     * @param token 令牌
     * @param id    店铺编号
     */
    public void memberCardInfo(String id, String token, StringCallback callback) {
        OkHttpUtils
                .post()
                .url(cardGet)
                .addParams("id", id)
                .addParams("token", token)
                .build()
                .execute(callback);
    }

    /**
     * 删除会员卡
     *
     * @param token 令牌
     * @param id    店铺编号
     */
    public void memberCardDelete(String id, String token, StringCallback callback) {
        OkHttpUtils
                .post()
                .url(cardDelete)
                .addParams("id", id)
                .addParams("token", token)
                .build()
                .execute(callback);
    }

    /**
     * 会员卡列表
     *
     * @param token      令牌
     * @param storeId    店铺编号
     * @param currentNum 当前页
     * @param currentNum 每一页显示个数
     */
    public void memberCardList(String storeId, String token, String currentNum, String pageSize, StringCallback callback) {
        OkHttpUtils
                .post()
                .url(cardList)
                .addParams("storeId", storeId)
                .addParams("token", token)
                .addParams("currentNum", currentNum)
                .addParams("pageSize", pageSize)
                .build()
                .execute(callback);
    }

    /**
     * 会员卡添加接口
     *
     * @param storeId
     * @param token
     * @param name      会员卡名
     * @param discount  折扣
     * @param notice    使用须知
     * @param limitTime 会员卡期限 1:无期限 2:有限制
     * @param startDate 有效期开始时间，limitTime为2时填写
     * @param endDate   有效期结束时间，limitTime为2时填写
     * @param status    会员卡状态1:生效2:失效 3：禁用
     * @param type      会员卡类型 1：普通（目前就一种）
     * @param callback
     */
    public void memberCardAdd(String storeId, String token, String name, String discount,
                              String notice, String limitTime, String startDate, String endDate,
                              String status, String type, StringCallback callback) {
        OkHttpUtils
                .post()
                .url(cardSave)
                .addParams("storeId", storeId)
                .addParams("token", token)
                .addParams("name", name)
                .addParams("discount", discount)
                .addParams("notice", notice)
                .addParams("limitTime", limitTime)
                .addParams("startDate", startDate)
                .addParams("endDate", endDate)
                .addParams("status", status)
                .addParams("type", type)
                .build()
                .execute(callback);
    }


    /**
     * 会员列表
     *
     * @param token      令牌
     * @param storeId    店铺编号
     * @param currentNum 当前页
     * @param currentNum 每一页显示个数
     */
    public void memberList(String storeId, String token, String currentNum, String pageSize, StringCallback callback) {
        OkHttpUtils
                .post()
                .url(memberList)
                .addParams("storeId", storeId)
                .addParams("token", token)
                .addParams("currentNum", currentNum)
                .addParams("pageSize", pageSize)
                .build()
                .execute(callback);
    }
}
